#ifndef __LUOO_MESSAGE_QUEUE_HPP__
#define __LUOO_MESSAGE_QUEUE_HPP__

#include <queue>

#include <boost/thread.hpp>

#include "luoo_typedef.h"

namespace luoo
{
	class message_queue
	{
	public:
		typedef struct
		{
			luoo::uint16 data_len;
			luoo::uint8* data_ptr;
		}message;

	public:
		bool empty()
		{
			boost::mutex::scoped_lock lock(mutex_);

			return message_queue_.empty();
		}

		void push(message& msg)
		{
			boost::mutex::scoped_lock lock(mutex_);

			message_queue_.push(msg);
		}

		luoo::uint8* pop()
		{
			boost::mutex::scoped_lock lock(mutex_);

			luoo::uint8* data_ptr = message_queue_.front().data_ptr;
			message_queue_.pop();
			return data_ptr;
		}

		message_queue::message& front()
		{
			boost::mutex::scoped_lock lock(mutex_);

			return message_queue_.front();
		}

	private:
		typedef std::queue<message> luoo_message_queue;

	private:
		luoo_message_queue message_queue_;
		boost::mutex mutex_;
	};
}

#endif//__LUOO_MESSAGE_QUEUE_HPP__